define(function(require, exports, module) {
    "use strict";
    var $ = require("$");
    var Monkey = require("./Monkey");
     require("./pwd");
    //登录

    

    if(window.cfg){

        var url = window.cfg.login;

        Monkey.placeholder(".placeholder");
        
        if($.cookie("loginName") && $.cookie("loginName")!= ""){
          $("#accounts").val($.cookie("loginName"));
        }

        $("input.txt").blur(function(){
          if($(this).val() == ""){
              $("#emptyInfo").fadeIn("slow");
              $("#hintInfo").fadeOut();
              $(this).prev("span.login-ico").removeClass("login-opacity");
          }else{
              $("#emptyInfo").fadeOut("slow");
          }
        });

        $("input.txt").focus(function(){
          $(this).prev("span.login-ico").addClass("login-opacity");
        });

        $(document).keydown(function(e){
          var curKey = e.which;
          if(curKey == 13){
          $("#login-submit").click();
          return false;
          }
        });
        
        $("div.login-from").on("click","#login-submit",function(){
          var userName = $("#accounts").val();
          var datas = {};
          var rem = $("#rememberId")[0].checked;
          if($("#accounts").val() == "" || $("#pwd").val() == "" || $("#accounts").val() == "请输入帐号" || $("#pwd").val()=="请输入密码"){
              $("#emptyInfo").fadeIn("slow");
              return;
          }

          datas.name = userName;
          datas.pwd = $("#pwd").val();
          datas.saveusername = rem;
          Monkey.post(url,function(d){
            if(d.status == 0){
                if(rem){
                  $.cookie("loginName",userName);
                }
                window.location.href = d.url;
            }else{
              $("#hintInfo").html(d.message).fadeIn("slow");
              $("#emptyInfo").fadeOut("hide");
            }
          },"",null,datas);
        })
      }
})
